package com.itheima.interpreter;

/**
 * @author zzw
 * @date 2025/10/26
 * @description 解释器模式（非终结符表达式类）
 */
public class Plus extends AbstractExpression {
    private final AbstractExpression left;
    private final AbstractExpression right;

    public Plus(AbstractExpression left, AbstractExpression right) {
        this.left = left;
        this.right = right;
    }

    @Override
    public int interpret(Context context) {
        return left.interpret(context) + right.interpret(context);
    }

    @Override
    public String toString() {
        return "(" + left.toString() + " + " + right.toString() + ")";
    }
}
